#include "msg.h"
#include "head.h"

/* Useage:  */

int recvMsg(int net_fd, CmdType *type, char * data){
    int len;
    int ret = recv(net_fd, &len, 4, MSG_WAITALL);
    ERROR_CHECK(ret, -1, "recv");
    recv(net_fd, type, 4, MSG_WAITALL);
    recv(net_fd, data, len, MSG_WAITALL);
    return 0;
}

int sendMsg(int net_fd, CmdType type, const char * data){
    msg_t msg;
    memset(&msg, 0, sizeof(msg));
    msg.len = strlen(data);
    msg.type = type;
    strcpy(msg.data, data);
    send(net_fd, &msg, msg.len + 8, MSG_WAITALL);

    return 0;
}
